package tdca.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import tdca.util.DataUtil;

public class Authentication extends Activity {
    LinearLayout layout_publicinfo = null;
    LinearLayout layout_threecode_match = null;

    TextView textview_threeCodeMatchResult = null;
    TextView text_publicInfoText = null;

    Button authentication_btn_success = null;
    Button authentication_btn_failed = null;
    Button authentication_btn_auThreeCode = null;
    Button authentication_btn_return = null;

    String[] publicInfo = null;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.authentication);

        layout_publicinfo = (LinearLayout) findViewById(R.id.authentication_publicInfo_layout);
        layout_threecode_match = (LinearLayout) findViewById(R.id.authentication_threecode_match_layout);

        textview_threeCodeMatchResult = (TextView) findViewById(R.id.authentication_threecode_result);
        text_publicInfoText = (TextView) findViewById(R.id.authentication_publicinfo_text);

        authentication_btn_success = (Button) findViewById(R.id.authentication_success);
        authentication_btn_failed = (Button) findViewById(R.id.authentication_failed);
        authentication_btn_auThreeCode = (Button) findViewById(R.id.authentication_btn_threeCode_Authenticate);
        authentication_btn_return = (Button) findViewById(R.id.authentication_returnto_mainui);
    }

    @Override
    protected void onResume() {
        super.onResume();    //To change body of overridden methods use File | Settings | File Templates.

        publicInfo = null;
        authentication_btn_return.setOnClickListener(new Listener_btn_return());
        if(DataUtil.instance().getMasterCode() != null){
            publicInfo = DataUtil.instance().getMasterInfo();
            String info = "姓名/性别/籍贯/民族/出生年月/学校/学号/入学年份/学生证编号/备注";
            String[] infos = info.split("/");
            StringBuffer echo = new StringBuffer();
            
            for(int i = 0;i<publicInfo.length-1;i++){
            	echo.append(infos[i]);
            	echo.append(":");
                echo.append("\t"+publicInfo[i]+"\n");
            }

            text_publicInfoText.setText(echo.toString());

            authentication_btn_success.setOnClickListener(new Listener_btn_success());
            authentication_btn_failed.setOnClickListener(new Listener_btn_failed());
            authentication_btn_auThreeCode.setOnClickListener(new Listener_btn_threeCode_Match());
        }else{
            Toast.makeText(Authentication.this,"请先扫描母章，再进入基本验证模块",Toast.LENGTH_SHORT).show();
            Authentication.this.finish();
        }
    }

    class Listener_btn_success implements Button.OnClickListener{
        public void onClick(View view) {
            //To change body of implemented methods use File | Settings | File Templates.
//        	DataUtil.instance().setFlag_0_publicInfo_Match_card(true);
            Toast.makeText(Authentication.this,"证件基本信息验证相符",Toast.LENGTH_SHORT).show();


        }
    }

    class Listener_btn_failed implements Button.OnClickListener{
        public void onClick(View view) {
            //To change body of implemented methods use File | Settings | File Templates.
//        	DataUtil.instance().setFlag_0_publicInfo_Match_card(false);
            Toast.makeText(Authentication.this,"证件基本信息验证不符",Toast.LENGTH_SHORT).show();
            Authentication.this.finish();
        }
    }

    class Listener_btn_threeCode_Match implements  Button.OnClickListener{
        @SuppressLint("ResourceAsColor")
		public void onClick(View view) {
            //To change body of implemented methods use File | Settings | File Templates.
           if(DataUtil.instance().getMasterCode() != null&&DataUtil.instance().getPrivateCode() != null&&DataUtil.instance().getSlaveCode() != null){
                if(DataUtil.instance().masterInfoHF_Match_slaveCodeDF()&&DataUtil.instance().privateCodeHF_Match_masterCodePI()){
                    textview_threeCodeMatchResult.setText("完全匹配");
                    Toast.makeText(Authentication.this,"子母印章族信息完全匹配",Toast.LENGTH_SHORT).show();
                }else{
                    textview_threeCodeMatchResult.setText("不匹配");
                    Toast.makeText(Authentication.this,"子母印章族信息不匹配",Toast.LENGTH_SHORT).show();

                    AlertDialog.Builder builder = new AlertDialog.Builder(Authentication.this);
                    builder.setTitle("警告").setMessage("子母印章族信息不匹配！").setIcon(R.drawable.wrong_1);
                    AlertDialog alertDialog = builder.create();
                    alertDialog.show();
                }
           }
        }
    }

    class Listener_btn_return implements View.OnClickListener{
        public void onClick(View view) {
            //To change body of implemented methods use File | Settings | File Templates.
            finish();
        }
    }
}